<?php
namespace Home\Behaviors;
/**
 * 6.7 
 * 基础行为扩展，主要用于登入检测与菜单生成
 * 菜单项相对比较固定，数目是动态的
 */
class BasicBehavior extends \Think\Behavior{
    //行为执行入口
    public function run(&$param){
        $str=strtolower($_SERVER['REQUEST_URI']);
    	//登入的用户加载菜单
    	if(session('?user')){
            //判断是否更改密码,密码不一致就退出
            $User = M('User');
            $result = $User->where('account="'.session('user.account').'"')->find();
            if($result&&$result['password'] != session('user.password')){
                session(null);
                redirect(U('Home/publicaction/user/login'));
            }
            session('user',$result);
            $Notice = M('Notice');

            //加载菜单
    		$menu = array();
    		$mail_count = $Notice->where('send_id='.session('user.user_id'))->count();//共有的
            session('notice',$mail_count);
    		switch (session('user.type')) {
    			case 'normal':
                    //没登入的用户进行跳转，注册登入和公有的操作不跳转
                    if(strpos($str, "superuser") ){
                        redirect(U('Home/User/User/basicinfo'));
                    }

    				$cart_count;
    				$comment_count;
    				$menu = array(
			            array("n"=>"1","c"=>"blue","url"=>U('Home/User/User/basicinfo'),"name"=>"基本信息",'icon'=>"fa-dashboard",'class'=>''),
			            array("n"=>"","c"=>"red","url"=>"order.html","name"=>"订单管理",'icon'=>"fa-files-o",'class'=>'order'),
			            array("n"=>"2","c"=>"yellow","url"=>"order.html","name"=>"购买历史",'icon'=>"fa-clock-o",'class'=>''),
			            array("n"=>$cart_count,"c"=>"blue","url"=>"order.html","name"=>"购物车",'icon'=>"fa-shopping-cart",'class'=>'cart'),
			            array("n"=>"","c"=>"red","url"=>"order.html","name"=>"收藏夹",'icon'=>"fa-heart",'class'=>''),
			            array("n"=>$comment_count,"c"=>"red","url"=>"order.html","name"=>"我的评论",'icon'=>"fa-comment",'class'=>'comment'),
			            array("n"=>"","c"=>"red","url"=>U("Home/User/User/editpwd"),"name"=>"修改密码",'icon'=>"fa-edit",'class'=>''),
			            array("n"=>"","c"=>"red","url"=>U('Home/User/address'),"name"=>"收货地址管理",'icon'=>"fa-map",'class'=>''),
			            array("n"=>$mail_count,"c"=>"red","url"=>U("Home/publicaction/Notice/index"),"name"=>"消息信箱",'icon'=>"fa-envelope",'class'=>'mailbox'),
			        );
    				break;    			
    			case 'super':
    				$menu = array(
                        array("n"=>"","c"=>"blue","url"=>U('Home/superuser/index'),"name"=>"控制面板",'icon'=>"fa-dashboard",'class'=>''),
                        array("n"=>"","c"=>"blue","url"=>U('Home/publicaction/order'),"name"=>"订单管理",'icon'=>"fa-tags",'class'=>''),
                        array("n"=>"","c"=>"blue","url"=>U('Home/superuser/trade'),"name"=>"财务管理",'icon'=>"fa-money",'class'=>'','child'=>
                            array(
                                array("url"=>U('Home/superuser/trade/'),"name"=>"平台交易管理"),
                                array("url"=>U('Home/superuser/trade/cash'),"name"=>"提现管理"),
                                array("url"=>U('Home/superuser/trade/recharge'),"name"=>"充值管理"),
                                // array("url"=>U(''),"name"=>"用户黑名单"),
                                )),
			            array("n"=>"","c"=>"blue","url"=>U('Home/superuser/user/index'),"name"=>"会员管理",'icon'=>"fa-user",'class'=>'','child'=>
                            array(
                                array("url"=>U('Home/superuser/user/index'),"name"=>"会员管理"),
                                array("url"=>U('Home/superuser/user/viprule'),"name"=>"会员规则管理"),
                                // array("url"=>U(''),"name"=>"用户黑名单"),
                                )),
                        array("n"=>"","c"=>"red","url"=>U('Home/Superuser/shop/listShop'),"name"=>"商家管理",'icon'=>"fa-desktop",'class'=>'','child'=>
                            array(
                                array("url"=>U("Home/superuser/shop/listShop/status/1"),"name"=>"商家申请审批"),
                                array("url"=>U('Home/superuser/shop/listShop/status/2'),"name"=>"商家管理"),
                                array("url"=>U('Home/superuser/shop/listShop/status/3'),"name"=>"商家黑名单"),
                                )),
                        array("n"=>"","c"=>"red","url"=>U('Home/superuser/SuperManager/listShop'),"name"=>"经纪人管理",'icon'=>"fa-group",'class'=>'','child'=>
                            array(
                                // array("url"=>U(""),"name"=>"经理人申请审批"),
                                // array("url"=>U(''),"name"=>"经理人管理"),
                                // array("url"=>U(''),"name"=>"经理人黑名单"),
                                )),
			            array("n"=>"","c"=>"red","url"=>U('Home/storekeeper/good'),"name"=>"商品管理",'icon'=>"fa-cubes",'class'=>'','child'=>
                            array(
                                // array("url"=>U("Home/storekeeper/good"),"name"=>"添加商品"),
                                array("url"=>U("Home/superuser/good/hotel"),"name"=>"酒店管理"),
                                array("url"=>U('home/superuser/Good/goodType'),"name"=>"种类管理"),
                                array("url"=>U('home/superuser/Good/manage'),"name"=>"商品管理"),
                                )),
                        array("n"=>"","c"=>"blue","url"=>U('Home/superuser/activity'),"name"=>"活动管理",'icon'=>"fa-money",'class'=>''),
                        array("n"=>$mail_count,"c"=>"red","url"=>U("Home/publicaction/notice/index"),"name"=>"消息信箱",'icon'=>"fa-envelope",'class'=>''),
			            // array("n"=>"","c"=>"red","url"=>U("Home/User/User/editpwd2"),"name"=>"修改密码",'icon'=>"fa-edit",'class'=>''),
                        array("n"=>"","c"=>"red","url"=>U('Home/User/User/basicinfo'),"name"=>"设置",'icon'=>"fa-gear",'class'=>'','child'=>
                            array(
                                array("url"=>U("Home/User/User/editpwd"),"name"=>"修改密码"),
                                array("url"=>U('Home/User/User/basicinfo'),"name"=>"个人信息"),
                                array("n"=>"","c"=>"red","url"=>U('Home/User/address'),"name"=>"收货地址管理",'icon'=>"fa-map",'class'=>''),
                                )
                        )
			        );
    				break;    			
    			case 'storekeeper':
                    //没登入的用户进行跳转，注册登入和公有的操作不跳转
                    if(strpos($str, "superuser") ){
                        redirect(U('Home/User/User/basicinfo'));
                    }
    				$menu = array(
			            array("n"=>"","c"=>"blue","url"=>"basicinfo.html","name"=>"基本信息",'icon'=>"fa-dashboard",'class'=>''),
			            array("n"=>"","c"=>"red","url"=>"order.html","name"=>"订单管理",'icon'=>"fa-files-o",'class'=>''),
			            array("n"=>$mail_count,"c"=>"red","url"=>U("Home/publicaction/Notice/index"),"name"=>"消息信箱",'icon'=>"fa-envelope",'class'=>''),
			        );
    				break;
    			
    			default:
    				echo "<script>alert('sss');</script>";
    				break;
    		}
    		session('menu',$menu);
    	}else{
    		//没登入的用户进行跳转，注册登入和公有的操作不跳转
    		if(!strpos($str, "publicaction")&&!strpos($str, "api")){
    			redirect(U('Home/publicaction/user/login'));
    		}
    	}
    	
    }
}